package com.relife.core.entity;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.relife.common.utils.DateUtil;
import com.relife.common.utils.StringUtil;
import org.springframework.web.multipart.MultipartFile;



@Entity
@Table(name = "sys_file")
public class FileEntity extends BaseEntity {

	private static final long serialVersionUID = -718053362500372730L;
	public static final String IMAGE = "image";
	public static final String FILE = "file";

	/** 文件名称 **/
	private String name;
	/** 文件路径 **/
	private String path;
	/** 文件路径 (小图片) **/
	private String minPath;
	/** 文件后缀 **/
	private String suffix;
	/** 上传类型，分别为image、flash、media、file **/
	private String dir;
	/** PDF文件路径 **/
	private String pdfPath;

	private Long fileSize;

	private transient MultipartFile file;
	private transient Integer width;
	private transient boolean domain = false;

	public FileEntity() {
		super();
	}

	public FileEntity(String id) {
		super.setId(id);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getMinPath() {
		return minPath;
	}

	public void setMinPath(String minPath) {
		this.minPath = minPath;
	}

	public String getSuffix() {
		return suffix;
	}

	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}

	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public String getPdfPath() {
		return pdfPath;
	}

	public void setPdfPath(String pdfPath) {
		this.pdfPath = pdfPath;
	}

	public Long getFileSize() {
		return fileSize;
	}

	public void setFileSize(Long fileSize) {
		this.fileSize = fileSize;
	}

	@Transient
	public MultipartFile getFile() {
		return file;
	}

	public void setFile(MultipartFile file) {
		this.file = file;
	}

	@Transient
	public String getFileName() {
		return DateUtil.getTime(DateUtil.YYYYMMDDHHMMSS) + StringUtil.getRandom(6);
	}

	@Transient
	public String getFileSuffix() {
		if( this.file != null ){
			String name = this.file.getOriginalFilename();
			return name.substring(name.lastIndexOf(".") + 1, name.length());
		}
		return null;
	}

	@Transient
	public Integer getWidth() {
		return width;
	}

	public void setWidth(Integer width) {
		this.width = width;
	}

	@Transient
	public boolean isDomain() {
		return domain;
	}

	public void setDomain(boolean domain) {
		this.domain = domain;
	}
}
